package com.example.tool.conf;

import cn.hutool.core.util.ObjectUtil;
import com.example.tool.bean.business.WarehouseInterceptionConfig;
import com.example.tool.service.RedisService;
import com.example.tool.util.DDUtil;
import com.example.tool.util.DateUtil;
import com.example.tool.util.ExpressDeliveryUtil.ExpressDeliveryResult;
import com.example.tool.util.ExpressDeliveryUtil.ExpressDeliveryTrack;
import com.example.tool.util.ExpressDeliveryUtil.TrackTypeEnum;
import com.example.tool.util.WeChatUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static com.example.tool.util.ExpressDeliveryUtil.TrackTypeEnum.RECEIVED;
import static com.example.tool.util.ExpressDeliveryUtil.TrackTypeEnum.SENDER;

@Component
public class WarehouseMsgConfig {
        private static RedisService redisService;
        public static HashMap<Integer,String>TYPE_KEY_TEMPLATE=new HashMap<>();
        public static final String collectionDelayKeyTemplate="sys:collectionDelay:%s";
        public static final String transferTimeoutKeyTemplate="sys:transferTimeout:%s";
        public static final String transferTimeoutAfterKeyTemplate="sys:transferTimeoutAfter:%s";
        public static final DateTimeFormatter FORMATTER_YYYY_MM = DateTimeFormatter.ofPattern("yyyy-MM");
        public static final  Integer readBatchSize=3000;
        public static final  Integer updateBatchSize=3000;
        public static final String keyTemplate="sys:sendOrderWorkbookId:%s:%s";
        //保存时间值
        public static final Integer dataSaveDays=7;
        //保存时间的单位
        public static final TimeUnit timeUnit = TimeUnit.DAYS;
        //揽收超时
        public static HashMap<String,WarehouseInterceptionConfig>WAREHOUSE_COLLECTION_DELAY_CONFIG=new HashMap<>();
        public static final String collectionDelayRangeAddressTemplate="A%s:E%s";//揽收
        public static final String collectionDelayMsgTitle="揽收超时预警通知-测试阶段";
        public static final List<String> collectionDelayHeaderValues=Arrays.asList("原始单号", "出库单号", "订单编号", "物流单号", "发货时间");
        public static final String collectionDelayMsgTemplate="原始单号：%s\n出库单号：%s\n订单编号：%s\n物流单号：%s\n发货时间：%s";
        public static final String collectionDelayEndingContent="订单类型：订单已发货未揽收，揽收即将超时，请优先处理揽收，并回传揽收成功记录。";

        //有揽无发
        public static HashMap<String,WarehouseInterceptionConfig>WAREHOUSE_WITHOUT_HAIR_CONFIG=new HashMap<>();
        public static final String withoutHairRangeAddressTemplate="A%s:E%s";//揽收
        public static final String withoutHairMsgTitle="有揽无发预警-测试阶段";
        public static final List<String> withoutHairHeaderValues=Arrays.asList("原始单号", "出库单号", "订单编号", "物流单号", "揽收时间");
        public static final String withoutHairMsgTemplate="原始单号：%s\n出库单号：%s\n订单编号：%s\n物流单号：%s\n揽收时间：%s";
        public static final String withoutHairEndingContent="订单类型：订单揽收后未及时更新转运/分拨记录，即将造成有揽无发，请及时更新中转。";

        //物流异常
        public static HashMap<String,List<WarehouseInterceptionConfig>>WAREHOUSE_LOGISTICS_ABNORMALITY_CONFIG=new HashMap<>();
        public static final String logisticsAbnormalityRangeAddressTemplate="A%s:D%s";//揽收
        public static final String logisticsAbnormalityMsgTitle="物流轨迹更新异常通知-测试阶段";
        public static final List<String> logisticsAbnormalityHeaderValues=Arrays.asList("原始单号", "出库单号", "订单编号", "物流单号");
        public static final String logisticsAbnormalityMsgTemplate="原始单号：%s\n出库单号：%s\n订单编号：%s\n物流单号：%s";
        public static final String logisticsAbnormalityEndingContent="订单类型：物流信息超24小时未更新，请及时更新物流轨迹，超48小时未更新按丢件处理。";
        public static final List<String>frozenWarehouseNos=Arrays.asList(
                WarehouseConfEnum.CQ_DP.getCode(),
                WarehouseConfEnum.HF_DP.getCode(),
                WarehouseConfEnum.TZ_DP.getCode(),
                WarehouseConfEnum.SH_DP.getCode(),
                WarehouseConfEnum.DX_DP.getCode(),
                WarehouseConfEnum.CS_DP.getCode(),
                WarehouseConfEnum.SY_DP.getCode(),
                WarehouseConfEnum.WH_DP.getCode());
        static {
                TYPE_KEY_TEMPLATE.put(0,collectionDelayKeyTemplate);
                TYPE_KEY_TEMPLATE.put(1,transferTimeoutKeyTemplate);
                TYPE_KEY_TEMPLATE.put(2,transferTimeoutAfterKeyTemplate);
        }


        static {//揽收超时
                WAREHOUSE_COLLECTION_DELAY_CONFIG.put(WarehouseConfEnum.LG_CW.getCode(),//苍南-龙港（常温仓）
                new WarehouseInterceptionConfig(//龙港仓（常温）审单对接群
                "93NwLYZXWybly4ANUvA9ylw9VkyEqBQm",
                WarehouseMsgSDConfEnum.LG_CW_SD.getSecret(),
                WarehouseMsgSDConfEnum.LG_CW_SD.getToken(),null,null));

                WAREHOUSE_COLLECTION_DELAY_CONFIG.put(WarehouseConfEnum.CQ_DP.getCode(),//重庆-中通（冻品仓）
                new WarehouseInterceptionConfig(//重庆仓（冻品）审单对接群
                "ydxXB52LJqelm3YKFnGgPo7eJqjMp697",
                WarehouseMsgSDConfEnum.CQ_DP_SD.getSecret(),
                WarehouseMsgSDConfEnum.CQ_DP_SD.getToken(),null,null));

//                WAREHOUSE_COLLECTION_DELAY_CONFIG.put("233565416",//广州-江高（常温仓）
//                new WarehouseInterceptionConfig(//江高仓（常温）审单对接群
//                "EpGBa2Lm8ajvKoMmIZ0PRP7QWgN7R35y",
//                "SEC71886d7de0e913186f1c34b796a5f8381b29537f327d3da2977b24d590c69a54",
//                "939653f7533235b20bb6f47b49517587c43c838f78de8f776e041f07eefdd8b3",null,null));
                WAREHOUSE_COLLECTION_DELAY_CONFIG.put(  WarehouseConfEnum.JG_CW.getCode(),//广州-江高（常温仓）
                new WarehouseInterceptionConfig(//江高仓（常温）督查群
                "m9bN7RYPWdXg9GkRIo0nNzAxWZd1wyK0",
                        WarehouseMsgKDConfEnum.JG_CW_DC_KD.getSecret(),
                        WarehouseMsgKDConfEnum.JG_CW_DC_KD.getToken(),null,null));





                WAREHOUSE_COLLECTION_DELAY_CONFIG.put(WarehouseConfEnum.HF_DP.getCode(),//合肥-肥西（冻品仓）
                new WarehouseInterceptionConfig(//合肥仓（冻品）审单对接群
                "EpGBa2Lm8ajvKoMmIZaXYq3XWgN7R35y",
                WarehouseMsgSDConfEnum.HF_DP_SD.getSecret(),
                WarehouseMsgSDConfEnum.HF_DP_SD.getToken(),null,null));

                WAREHOUSE_COLLECTION_DELAY_CONFIG.put(WarehouseConfEnum.TZ_DP.getCode(),//济南-天泽（冻品仓）
                new WarehouseInterceptionConfig(//天泽仓（冻品）审单对接群
                "mExel2BLV5yX62NDIEAj9GnZVgk9rpMq",
                WarehouseMsgSDConfEnum.TZ_DP_SD.getSecret(),
                WarehouseMsgSDConfEnum.TZ_DP_SD.getToken(),null,null));

                WAREHOUSE_COLLECTION_DELAY_CONFIG.put(WarehouseConfEnum.SH_DP.getCode(),//上海-上海（冻品仓）
                new WarehouseInterceptionConfig(//上海仓 （冻品）审单对接群
                "YMyQA2dXW7r3K2XMF60nPl2k8zlwrZgb",
                WarehouseMsgSDConfEnum.SH_DP_SD.getSecret(),
                WarehouseMsgSDConfEnum.SH_DP_SD.getToken(),null,null));

                WAREHOUSE_COLLECTION_DELAY_CONFIG.put(WarehouseConfEnum.DX_DP.getCode(),//广州-德信（冻品仓）
                new WarehouseInterceptionConfig(//德信仓 （冻品）审单对接群
                "kDnRL6jAJMDAYjEwHDv9Ej3rVyMoPYe1",
                WarehouseMsgSDConfEnum.DX_DP_SD.getSecret(),
                WarehouseMsgSDConfEnum.DX_DP_SD.getToken(),null,null));

                WAREHOUSE_COLLECTION_DELAY_CONFIG.put(WarehouseConfEnum.JX_CW.getCode(),//江西-南昌（常温仓）
                new WarehouseInterceptionConfig(//江西仓（常温）审单对接群
                "QOG9lyrgJPjOxAErIBdmov0kWzN67Mw4",
                WarehouseMsgSDConfEnum.JX_CW_SD.getSecret(),
                WarehouseMsgSDConfEnum.JX_CW_SD.getToken(),null,null));

                WAREHOUSE_COLLECTION_DELAY_CONFIG.put(WarehouseConfEnum.CS_DP.getCode(),//长沙-中通（冻品仓）
                new WarehouseInterceptionConfig(//长沙仓（冻品）审单对接群
                "Obva6QBXJw6lYwAMFlx7YB55Vn4qY5Pr",
                WarehouseMsgSDConfEnum.CS_DP_SD.getSecret(),
                WarehouseMsgSDConfEnum.CS_DP_SD.getToken(),null,null));

                WAREHOUSE_COLLECTION_DELAY_CONFIG.put(WarehouseConfEnum.CS_CW.getCode(),//湖南-长沙（常温仓）
                new WarehouseInterceptionConfig(//长沙仓（常温）审单对接群
                "QG53mjyd80yjGN9lId9x46RxW6zbX04v",
                WarehouseMsgSDConfEnum.CS_CW_SD.getSecret(),
                WarehouseMsgSDConfEnum.CS_CW_SD.getToken(),null,null));

                WAREHOUSE_COLLECTION_DELAY_CONFIG.put(WarehouseConfEnum.YW_CW.getCode(),//浙江-义乌（常温仓）
                new WarehouseInterceptionConfig(//义乌仓 （常温）审单对接群
                "jb9Y4gmKWrblnwA4UaXvBdXoWGXn6lpz",
                WarehouseMsgSDConfEnum.YW_CW_SD.getSecret(),
                WarehouseMsgSDConfEnum.YW_CW_SD.getToken(),null,null));

                WAREHOUSE_COLLECTION_DELAY_CONFIG.put(WarehouseConfEnum.SY_DP.getCode(),//沈阳-天泽（冻品仓）
                new WarehouseInterceptionConfig(//沈阳仓（冻品）审单对接群
                "ZX6GRezwJlyDpZnPIn42vwaN8dqbropQ",
                        WarehouseMsgSDConfEnum.SY_DP_SD.getToken(),
                        WarehouseMsgSDConfEnum.SY_DP_SD.getToken(),
                        null,null));

                WAREHOUSE_COLLECTION_DELAY_CONFIG.put(WarehouseConfEnum.WH_DP.getCode(),//武汉（冻品仓）
                new WarehouseInterceptionConfig(//武汉仓（冻品）审单对接群
                "gvNG4YZ7JnbMzLR5UyPe42eXJ2LD0oRE",
                        WarehouseMsgSDConfEnum.WH_DP_SD.getToken(),
                        WarehouseMsgSDConfEnum.WH_DP_SD.getToken(),null,null));
        }

        static {//有揽无发
        WAREHOUSE_WITHOUT_HAIR_CONFIG.put(WarehouseConfEnum.LG_CW.getCode(),//苍南-龙港（常温仓）
        new WarehouseInterceptionConfig(//龙港仓（常温）审单对接群
        "vy20BglGWOMOykAqTl601wYaJA7depqY",
        WarehouseMsgSDConfEnum.LG_CW_SD.getSecret(),
        WarehouseMsgSDConfEnum.LG_CW_SD.getToken(),null,null)
        );


        WAREHOUSE_WITHOUT_HAIR_CONFIG.put(WarehouseConfEnum.CQ_DP.getCode(),//重庆-中通（冻品仓）
        new WarehouseInterceptionConfig(//重庆仓（冻品）审单对接群
        "QOG9lyrgJPjOxAErIBdzBRMOWzN67Mw4",
        WarehouseMsgSDConfEnum.CQ_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.CQ_DP_SD.getToken(),null,null)

        );

        WAREHOUSE_WITHOUT_HAIR_CONFIG.put(  WarehouseConfEnum.JG_CW.getCode(),//广州-江高（常温仓）
        new WarehouseInterceptionConfig(//江高仓（常温）审单对接群
        "r1R7q3QmWepMDOX0U7rN2QE08xkXOEP2",
        WarehouseMsgKDConfEnum.JG_CW_DC_KD.getSecret(),
        WarehouseMsgKDConfEnum.JG_CW_DC_KD.getToken(),null,null));

        WAREHOUSE_WITHOUT_HAIR_CONFIG.put(WarehouseConfEnum.HF_DP.getCode(),//合肥-肥西（冻品仓）
        new WarehouseInterceptionConfig(//合肥仓（冻品）审单对接群
        "2Amq4vjg89eqvP2NFdNmgR4x83kdP0wQ",
        WarehouseMsgSDConfEnum.HF_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.HF_DP_SD.getToken(),null,null)
        );

        WAREHOUSE_WITHOUT_HAIR_CONFIG.put(WarehouseConfEnum.TZ_DP.getCode(),//济南-天泽（冻品仓）
        new WarehouseInterceptionConfig(//天泽仓（冻品）审单对接群
        "QOG9lyrgJPjOxAErIBdbkGlDWzN67Mw4",
        WarehouseMsgSDConfEnum.TZ_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.TZ_DP_SD.getToken(),null,null)
        );

        WAREHOUSE_WITHOUT_HAIR_CONFIG.put(WarehouseConfEnum.SH_DP.getCode(),//上海-上海（冻品仓）
        new WarehouseInterceptionConfig(//上海仓 （冻品）审单对接群
        "r1R7q3QmWepMDOX0U7r6AmL18xkXOEP2",
        WarehouseMsgSDConfEnum.SH_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.SH_DP_SD.getToken(),null,null)
        );
        WAREHOUSE_WITHOUT_HAIR_CONFIG.put(WarehouseConfEnum.DX_DP.getCode(),//广州-德信（冻品仓）
        new WarehouseInterceptionConfig(//德信仓 （冻品）审单对接群
        "gwva2dxOW4yp12j9IdrYmbB1Vbkz3BRL",
        WarehouseMsgSDConfEnum.DX_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.DX_DP_SD.getToken(),null,null)
        );

        WAREHOUSE_WITHOUT_HAIR_CONFIG.put(WarehouseConfEnum.JX_CW.getCode(),//江西-南昌（常温仓）
        new WarehouseInterceptionConfig(//江西仓（常温）审单对接群
        "7NkDwLng8ZK3GnEkTj93eLZMWKMEvZBY",
        WarehouseMsgSDConfEnum.JX_CW_SD.getSecret(),
        WarehouseMsgSDConfEnum.JX_CW_SD.getToken(),null,null)
        );

        WAREHOUSE_WITHOUT_HAIR_CONFIG.put(WarehouseConfEnum.CS_DP.getCode(),//长沙-中通（冻品仓）
        new WarehouseInterceptionConfig(//长沙仓（冻品）审单对接群
        "dQPGYqjpJYm0ALeNide9OMj9Jakx1Z5N",
        WarehouseMsgSDConfEnum.CS_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.CS_DP_SD.getToken(),null,null)
        );

        WAREHOUSE_WITHOUT_HAIR_CONFIG.put(WarehouseConfEnum.CS_CW.getCode(),//湖南-长沙（常温仓）
        new WarehouseInterceptionConfig(//长沙仓（常温）审单对接群
        "G1DKw2zgV2yXd0g4ILEdwR7qWB5r9YAn",
        WarehouseMsgSDConfEnum.CS_CW_SD.getSecret(),
        WarehouseMsgSDConfEnum.CS_CW_SD.getToken(),null,null)
        );

        WAREHOUSE_WITHOUT_HAIR_CONFIG.put(WarehouseConfEnum.YW_CW.getCode(),//浙江-义乌（常温仓）
        new WarehouseInterceptionConfig(//义乌仓 （常温）审单对接群
        "vy20BglGWOMOykAqTl6DPeOoJA7depqY",
        WarehouseMsgSDConfEnum.YW_CW_SD.getSecret(),
        WarehouseMsgSDConfEnum.YW_CW_SD.getToken(),null,null));

        WAREHOUSE_WITHOUT_HAIR_CONFIG.put(WarehouseConfEnum.SY_DP.getCode(),//沈阳-天泽（冻品仓）
        new WarehouseInterceptionConfig(//沈阳仓（冻品）审单对接群
        "dpYLaezmVNgO3NE5iZRNxEQ2JrMqPxX6",
        WarehouseMsgSDConfEnum.SY_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.SY_DP_SD.getToken(),
        null,null));

        WAREHOUSE_WITHOUT_HAIR_CONFIG.put(WarehouseConfEnum.WH_DP.getCode(),//武汉（冻品仓）
        new WarehouseInterceptionConfig(//武汉仓（冻品）审单对接群
        "kDnRL6jAJMDAYjEwHDvAKD11VyMoPYe1",
        WarehouseMsgSDConfEnum.WH_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.WH_DP_SD.getToken(),null,null));
        }

        static {//物流异常
        WAREHOUSE_LOGISTICS_ABNORMALITY_CONFIG.put(WarehouseConfEnum.LG_CW.getCode(),//苍南-龙港（常温仓）
        Arrays.asList(new WarehouseInterceptionConfig(//龙港仓（常温）快递售后群（申通）
        "14lgGw3P8vLlreAgtdKL6qb9V5daZ90D",
        WarehouseMsgSDConfEnum.LG_CW_SD.getSecret(),
        WarehouseMsgSDConfEnum.LG_CW_SD.getToken(),null,null))
        );


        WAREHOUSE_LOGISTICS_ABNORMALITY_CONFIG.put(WarehouseConfEnum.CQ_DP.getCode(),//重庆-中通（冻品仓）
        Arrays.asList(new WarehouseInterceptionConfig(//重庆仓（冻品）快递售后群
        "lyQod3RxJKvm0gEOCPvXv5rxVkb4Mw9r",
        WarehouseMsgSDConfEnum.CQ_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.CQ_DP_SD.getToken(),null,null))
        );

        WAREHOUSE_LOGISTICS_ABNORMALITY_CONFIG.put(WarehouseConfEnum.JG_CW.getCode(),//广州-江高（常温仓）
        Arrays.asList(
        new WarehouseInterceptionConfig(//江高仓（常温）督察群
        "oP0MALyR8kb9XAmOUEpgx3oZJ3bzYmDO",
        WarehouseMsgKDConfEnum.JG_CW_DC_KD.getSecret(),
        WarehouseMsgKDConfEnum.JG_CW_DC_KD.getToken(),null,null)
        ));

        WAREHOUSE_LOGISTICS_ABNORMALITY_CONFIG.put(WarehouseConfEnum.HF_DP.getCode(),//合肥-肥西（冻品仓）
        Collections.singletonList(new WarehouseInterceptionConfig(//台肥仓（冻品）快递售后群（统一）
        "dpYLaezmVNgO3NE5iZROqbydJrMqPxX6",
        WarehouseMsgSDConfEnum.HF_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.HF_DP_SD.getToken(),null,null)
        ));

        WAREHOUSE_LOGISTICS_ABNORMALITY_CONFIG.put(WarehouseConfEnum.TZ_DP.getCode(),//济南-天泽（冻品仓）
        Arrays.asList( new WarehouseInterceptionConfig(//天泽仓（冻品）快递售后群（统一）
        "7NkDwLng8ZK3GnEkTj9MPNoXWKMEvZBY",
        WarehouseMsgSDConfEnum.TZ_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.TZ_DP_SD.getToken(),null,null))
        );

        WAREHOUSE_LOGISTICS_ABNORMALITY_CONFIG.put(WarehouseConfEnum.SH_DP.getCode(),//上海-上海（冻品仓）
        Arrays.asList( new WarehouseInterceptionConfig(//上海仓（冻品）快递售后群
        "ZgpG2NdyVXaOEALjT3p924qxJMwvDqPk",
        WarehouseMsgSDConfEnum.SH_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.SH_DP_SD.getToken(),null,null))
        );


        WAREHOUSE_LOGISTICS_ABNORMALITY_CONFIG.put(WarehouseConfEnum.DX_DP.getCode(),//广州-德信（冻品仓）
        Arrays.asList( new WarehouseInterceptionConfig(//德信仓（冻品）快递售后群
        "KGZLxjv9VGdRm4EYC7vZE5yBJ6EDybno",
                WarehouseMsgSDConfEnum.DX_DP_SD.getSecret(),
                WarehouseMsgSDConfEnum.DX_DP_SD.getToken(),null,null))
        );

        WAREHOUSE_LOGISTICS_ABNORMALITY_CONFIG.put(WarehouseConfEnum.JX_CW.getCode(),//江西-南昌（常温仓）
        Arrays.asList(
        new WarehouseInterceptionConfig(//江西仓（常温）快递售后群（中通）
        "P7QG4Yx2Jp3NaeblUYd36exQV9dEq3XD",
        WarehouseMsgSDConfEnum.JX_CW_SD.getSecret(),
        WarehouseMsgSDConfEnum.JX_CW_SD.getToken(),null,null))
        );

        WAREHOUSE_LOGISTICS_ABNORMALITY_CONFIG.put(WarehouseConfEnum.CS_DP.getCode(),//长沙-中通（冻品仓）
        Collections.singletonList(new WarehouseInterceptionConfig(//长沙仓（冻品）快递售后群（统一）
        "ZX6GRezwJlyDpZnPIn42Ar0X8dqbropQ",
        WarehouseMsgSDConfEnum.CS_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.CS_DP_SD.getToken(),null,null))
        );

        WAREHOUSE_LOGISTICS_ABNORMALITY_CONFIG.put(WarehouseConfEnum.CS_CW.getCode(),//湖南-长沙（常温仓）
        Collections.singletonList(new WarehouseInterceptionConfig(//长沙仓（常温）快递售后群（统一）
        "Gl6Pm2Db8DemzxdRFqalaDrOWxLq0Ee4",
        WarehouseMsgSDConfEnum.CS_CW_SD.getSecret(),
        WarehouseMsgSDConfEnum.CS_CW_SD.getToken(),null,null))
        );


        WAREHOUSE_LOGISTICS_ABNORMALITY_CONFIG.put(WarehouseConfEnum.YW_CW.getCode(),//浙江-义乌（常温仓）
        Collections.singletonList(new WarehouseInterceptionConfig(//义乌仓 （常温）快递售后群（统一）
        "2Amq4vjg89eqvP2NFdNGgYLa83kdP0wQ",//正式
        WarehouseMsgSDConfEnum.YW_CW_SD.getSecret(),
        WarehouseMsgSDConfEnum.YW_CW_SD.getToken(),null,null))
        );

        WAREHOUSE_LOGISTICS_ABNORMALITY_CONFIG.put(WarehouseConfEnum.SY_DP.getCode(),//沈阳-天泽（冻品仓）
        Collections.singletonList(new WarehouseInterceptionConfig(//沈阳仓（冻品）审单对接群
        "EpGBa2Lm8ajvKoMmIZaGdm62WgN7R35y",
        WarehouseMsgSDConfEnum.SY_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.SY_DP_SD.getToken(),null,null))

        );

        WAREHOUSE_LOGISTICS_ABNORMALITY_CONFIG.put(WarehouseConfEnum.WH_DP.getCode(),//武汉（冻品仓）
        Collections.singletonList(new WarehouseInterceptionConfig(//武汉仓（冻品）审单对接群
        "MNDoBb60VL9ObMEPFrM1gz3OJlemrZQ3",
        WarehouseMsgSDConfEnum.WH_DP_SD.getSecret(),
        WarehouseMsgSDConfEnum.WH_DP_SD.getToken(),null,null)));
        }

        @Autowired
        public void setRedisService(RedisService redisService) {
                WarehouseMsgConfig.redisService = redisService;
        }

//        public static void updateDocumentSending(Integer platform, String workbookId, String secret, String token, List<String> atMobiles, List<String> atUserIds, List<List<String>>values,
//                                           String sheetId, List<String> headerValues, String msgTitle, String msgTemplate, String endingContent, String rangeAddressTemplate, Integer updateBatchSize, Integer dataSaveDays, TimeUnit timeUnit, String keyTemplate){
//                //平台 1钉钉 2企业微信
//                if(ObjectUtil.equals(platform,1)){
//                        DDUtil.updateDocumentSending(workbookId,secret,token,atMobiles,atUserIds,values,sheetId,headerValues,msgTitle,msgTemplate,endingContent,rangeAddressTemplate,updateBatchSize,dataSaveDays,timeUnit,keyTemplate);
//                }else {
//                        WeChatUtil.updateDocumentSending(workbookId,secret,token,atMobiles,atUserIds,values,sheetId,headerValues,msgTitle,msgTemplate,endingContent,rangeAddressTemplate,updateBatchSize,dataSaveDays,timeUnit,keyTemplate);
//                }
//        }

        public static void updateAiExcelSendMsg(Integer platform,String workbookId,String secret,String token,List<String> atMobiles,List<String> atUserIds,List<List<String>>values,
                                          String sheetName,List<String> headerValues,String msgTitle,String msgTemplate,String endingContent,Integer updateBatchSize){
                //平台 1钉钉 2企业微信
                if(ObjectUtil.equals(platform,1)){
                        DDUtil.updateAiExcelSendMsg(workbookId,secret,token,atMobiles,atUserIds,values,sheetName,headerValues,msgTitle,msgTemplate,endingContent,updateBatchSize);
                }else {
                        WeChatUtil.updateAiExcelSendMsg(workbookId,secret,token,atMobiles,atUserIds,values,sheetName,headerValues,msgTitle,msgTemplate,endingContent,updateBatchSize);
                }
        }

        public static Integer nextStep(List<ExpressDeliveryTrack> tracks){
        Integer type=null;
        int size=tracks.size();
        List<ExpressDeliveryTrack>dItem=tracks.stream().filter(t -> ObjectUtil.equal(t.getScanType(), TrackTypeEnum.DELIVERY.getCode())).collect(Collectors.toList());
        int dIndex=tracks.indexOf(dItem);
        if(size==0||(size==dIndex||dIndex==-1)){
        switch (size){
                case 0: type=0;break;
                case 1:  type=1;break;
                default: type=2;
        }
        }
        return type;
        }




        public static void logisticsMonitoring(ExpressDeliveryResult result){
                //        if (succeed){
                List<ExpressDeliveryTrack> tracks = result.getTracks();
                if (tracks.isEmpty()){
                        return;
                }
                ExpressDeliveryTrack track = tracks.get(0);
                String logisticsNo = result.getWaybillNo();
                String scanType = track.getScanType();
//            Boolean isCenter = track.getIsCenter();
//            Boolean isTransfer = track.getIsTransfer();
//            String desc = track.getDesc();

                Date now = new Date();
                Date scanDate = track.getScanDate();
//            Date outTime =null;
                //        }
                /**
                 * 揽收超时 发货后超过24小时未揽收
                 * 中转超时 揽收后 一直到中转每个步骤 超过24小时不更新 都算
                 * 中转后物流异常  第一次到了中转以后每次物流超过24小时不更新
                 *
                 * 状态是
                 * 揽收 删除揽收超时KEY  储存 中转超时
                 * 发送中转   删除原来中转超时key 保存新的中转超时key
                 * 抵达中转   删除中转超时key  设置物流异常的key
                 * 。。      删除原来物流异常的key 保存新的物流异常的key
                 * 签收（结束不判断）删除所有key
                 *
                 * 设置过期时间为 24小时 到期后判断是否未到中转站
                 * 并删除揽收超时KEY
                 *
                 * 到中转设置
                 * 判断是否是揽收 揽收判断揽收超时
                 *
                 */
                String transferTimeoutKey="";
                String transferTimeoutAfterKey="";
                String collectionDelayKey="";
                Long timeDifference =0L;
                switch (scanType){
                        case "NOT_COLLECTED":
                                break;//未知
                        case "COLLECTION":
                                collectionDelayKey=String.format(collectionDelayKeyTemplate,logisticsNo);
                                redisService.delete(collectionDelayKey);
                                transferTimeoutAfterKey=String.format(transferTimeoutKeyTemplate,logisticsNo);
                                timeDifference = DateUtil.findTimeDifference(now, DateUtil.addHourDate(scanDate, 24));
                                redisService.setWithExpire(transferTimeoutAfterKey,"",timeDifference, TimeUnit.SECONDS);
                                break;//揽收
                        case "SENDER":
                        case "RECEIVED":
                                //判断是否第一次发完或者到达中转站
                                long toTransitNum = tracks.stream().filter(e -> e.getIsTransfer() && ObjectUtil.equal(e.getScanType(), RECEIVED.getCode())).count();
                                if(ObjectUtil.equal(scanType,SENDER.getCode())){//发件
                                if(toTransitNum==0){//第一次 发往中转站 跳过
                                   return;
                                }
                                //不是第一次发中转站 设置物流异常key
                                collectionDelayKey=String.format(transferTimeoutAfterKeyTemplate,logisticsNo);
                                redisService.delete(collectionDelayKey);
                                transferTimeoutAfterKey=String.format(transferTimeoutAfterKeyTemplate,logisticsNo);
                                timeDifference = DateUtil.findTimeDifference(now, DateUtil.addHourDate(scanDate, 24));
                                redisService.setWithExpire(transferTimeoutAfterKey,"",timeDifference, TimeUnit.SECONDS);
                                }else{//到件
                                if (toTransitNum==1){//第一次到中转站
                                        collectionDelayKey=String.format(transferTimeoutKeyTemplate,logisticsNo);
                                        redisService.delete(collectionDelayKey);
                                        transferTimeoutAfterKey=String.format(transferTimeoutAfterKeyTemplate,logisticsNo);
                                        timeDifference = DateUtil.findTimeDifference(now, DateUtil.addHourDate(scanDate, 24));
                                        redisService.setWithExpire(transferTimeoutAfterKey,"",timeDifference, TimeUnit.SECONDS);
                                }else {//不是第一次到中转站
                                        collectionDelayKey=String.format(transferTimeoutAfterKeyTemplate,logisticsNo);
                                        redisService.delete(collectionDelayKey);
                                        transferTimeoutAfterKey=String.format(transferTimeoutAfterKeyTemplate,logisticsNo);
                                        timeDifference = DateUtil.findTimeDifference(now, DateUtil.addHourDate(scanDate, 24));
                                        redisService.setWithExpire(transferTimeoutAfterKey,"",timeDifference, TimeUnit.SECONDS);
                                }


                                }

//                                if(ObjectUtil.equal(scanType,SENDER.getCode())&&toTransitNum==0){
//                                        return;
//                                }

                                //第一次 发中转站 跳过
                                //第一次 到中转站 删除啊 transferTimeoutKeyTemplate 添加 transferTimeoutAfterKeyTemplate

                                //第二次 发中转站 删除 old transferTimeoutAfterKeyTemplate 添加 newTransferTimeoutAfterKeyTemplate
                                //第二次 到中转站 删除 old transferTimeoutAfterKeyTemplate 添加 newTransferTimeoutAfterKeyTemplate



//                    collectionDelayKey=String.format(transferTimeoutKeyTemplate,logisticsNo);
//                    redisService.delete(collectionDelayKey);
//                    transferTimeoutAfterKey=String.format(transferTimeoutKeyTemplate,logisticsNo);
//                    timeDifference = DateUtil.findTimeDifference(now, DateUtil.addHourDate(scanDate, 24));
//                    redisService.setWithExpire(transferTimeoutAfterKey,"",timeDifference, TimeUnit.SECONDS);

                                break;//到件
                        case "DELIVERY":
                                //                break;//派件
                        case "ARRIVAL":
                                collectionDelayKey=String.format(transferTimeoutAfterKeyTemplate,logisticsNo);
                                redisService.delete(collectionDelayKey);
                                transferTimeoutAfterKey=String.format(transferTimeoutAfterKeyTemplate,logisticsNo);
                                timeDifference = DateUtil.findTimeDifference(now, DateUtil.addHourDate(scanDate, 24));
                                redisService.setWithExpire(transferTimeoutAfterKey,"",timeDifference, TimeUnit.SECONDS);
                                break;//代收
                        //            case "TRANSFER_ORDER":
                        //
                        //                break;//转单
                        //            case "GIVEBACK":
                        //
                        //                break;//退回
                        case "SIGNED":
                                transferTimeoutAfterKey=String.format(transferTimeoutAfterKeyTemplate,logisticsNo);
                                //                 redisService.delete(collectionDelayKey);
                                redisService.delete(transferTimeoutAfterKey);

                                break;//签收
                }
        }
}
